package com.lang.springbootinit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Array;

@RestController
public class HelloWorldController {
    @Value("${name}")
    private  String name;
    @Value("${arr[0]}")
    private int arr;
    @Value("${obj.password}")
    private String password;
    @Value("username")
    private String username;

    @Autowired
    private Environment env;

    @RequestMapping("/hello")
    public String hello(){
        System.out.println(name);
        System.out.println(arr);
        System.out.println(password);
        System.out.println(username);
        System.out.println(env.getProperty("obj.password"));
        System.out.println(env.getProperty("arr[0]"));
        return "hello world";
    }

    @Autowired
    private Person person;

    @RequestMapping("/hello2")
    public String hello2(){
        System.out.println(person);
        String[] address = person.getAddress();
        for (String s : address) {
            System.out.println(s);
        }
        return "hello world2";
    }
}
